package com.extremeforce.function;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class GetNetImage {

	private static final String website = "http://www.ravio.org/couponimages/";
	private static final String url = "http://10.0.2.2:8080/IGuangWeb/couponimages/";
	
	public static Bitmap  getImage(String path){
		path = website + path;
		Bitmap bm = null;
		try{
			byte[] data = NetTool.getImage(path);
			bm = BitmapFactory.decodeByteArray(data,0,data.length);
		}catch(Exception e){
			return null;
		}
		return bm;
	}
	
	public static Bitmap byteArrayToImage(byte[] data){
		Bitmap bm = BitmapFactory.decodeByteArray(data,0,data.length);
		return bm;
	}
	
	public static byte[] getBytes(String path){
		byte[] data = null;
		try {
			data = NetTool.getImage(path);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;		
	}
	
	public static byte[] imageToBytes(Bitmap bmp){
		ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
		if(bmp != null)
			bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);  
	      
	    return baos.toByteArray(); 
	}
}
